<?php 

class ConnexionModel extends CI_Model {
    
    function login($login, $password)
    {
		$this->db->select('iduser, login, password, nom, prenom, typeuser');
		$this->db->from('user');
		$this->db->where('login', $login);
		$this->db->where('password', ($password));
		$this->db->limit(1);

		$query = $this->db->get();

		if ($query->num_rows() == 1) {
			$result = $query->result();
			$this->session->set_userdata('nomEtudiant', $result[0]->prenom . " " . strtoupper($result[0]->nom));
			$this->session->set_userdata('id', $result[0]->iduser);
			$this->session->set_userdata('typeuser', $result[0]->typeuser);
			
			return true;
		} else {
			return false;
		}
	}
	
    function verifconnexion()
    {
		
		$userId = $this->session->userdata('id');
		
		$this->db->select('iduser');
		$this->db->from('user');
		$this->db->where('iduser', $userId);
        $this->db->where('enAttenteValidation',0);
		$this->db->limit(1);

		$query = $this->db->get();

		if ($query->num_rows() > 0) {			
			return true;
		} else {
			return false;
		}
	}
	
    function verifadmin()
    {
		
		$userId = $this->session->userdata('id');
		
		$this->db->select('iduser');
		$this->db->from('user');
		$this->db->where('iduser', $userId);
        $this->db->where('enAttenteValidation',0);
        $this->db->where('typeuser', 3);
		$this->db->limit(1);

		$query = $this->db->get();

		if ($query->num_rows() > 0) {			
			return true;
		} else {
			return false;
		}
	}
}